using UnityEngine;
using System.Collections;

public class PlayerSpawner : MonoBehaviour {
	public int pNum;
	public Transform player, player2, player3, player4;
	void OnNetworkLoadedLevel1(){
		playerManager p = GameObject.Find("playerManager").GetComponent<playerManager>();
		if(p.p1 == false){
			Network.Instantiate(player,transform.position,transform.rotation,0);
			pNum = 1;
			p.addPlayer(pNum);
		}
		else if(p.p2 == false){
			Network.Instantiate(player2,transform.position,transform.rotation,0);
			pNum = 2;
			p.addPlayer(pNum);
		}
		else if(p.p3 == false){
			Network.Instantiate(player3,transform.position,transform.rotation,0);
			pNum = 3;
			p.addPlayer(pNum);
		}
		else if(p.p4 == false){
			Network.Instantiate(player4,transform.position,transform.rotation,0);
			pNum = 4;
			p.addPlayer(pNum);
		}
	}
	void OnPlayerDisconnected(NetworkPlayer player){
		playerManager p = GameObject.Find("playerManager(Clone)").GetComponent<playerManager>();
		Network.RemoveRPCs(player,0);
		Network.DestroyPlayerObjects(player);
		p.removePlayer(pNum);
	}

}
